Workshop: Linear Mixed Models in jamovi

Author

Armando Teixeira-Pinto

Published

July 1, 2025

1 Quick Background

  • Linear Mixed Models (LMMs): LMMs extend linear regression to account for clustered (correlated) data, such as repeated measures on subjects. They include fixed effects (e.g., treatment, time) for population-level trends and random effects (e.g., random intercepts or slopes per subject) to model within-subject correlation and heterogeneity.
  • Key Components:
    • Fixed Effects: Coefficients for predictors like treatment (trt) and time.
    • Random Effects: Typically (1|id) for random intercepts (subject-specific baseline), or (time|id) for random slopes (individual time trends).
  • Assumptions: Linearity, normality of residuals/random effects, homoscedasticity; handles missing data under MAR.
  • Here: We’ll analyze strength gains over time by treatment group using the Linear Mixed Models module in Jamovi. Outcome: strength (y); Predictor: time (days); Group: trt (1=increase reps, 2=increase weight); Clustering: subject id.

The dataset has 37 subjects (16 in trt=1, 21 in trt=2), with up to 7 measurements (assuming time points at months 0,2,4,6,8,10,12 .

Note: Run in Jamovi. Download and save the provided stren_long.csv file (long format) in your working directory, or load it directly.

2 Install and Load Modules

Jamovi comes with core modules, but for Linear Mixed Models, ensure the “Linear Mixed Models” module is installed (part of the jamovi library).

  • Open Jamovi.
  • Go to the “+” (modules) button in the top-right toolbar.
  • Search for “Rj - Editor” and install it if not already present.
  • Search for “jReshape” and install it if not already present.
  • Search for “Linear Models” and install “GAMLj3” it if not already present.
  • Restart Jamovi if prompted.

Install Modules

Install Modules
  • What this does:
    • The Rj-Editor allows you run R code withig jamovi.
    • The jReshape module allow to to go from the wide-format data to the long-format data. (not used in this example)
    • The GAMLv3 has implemented the linear mixed models interface for fitting LMMs; the Regression module adds ordinary least squares for comparison.
  • Expected output: Modules appear in the Analyses bar or in the “+” sign under *jamovi library”

3 Load the data

Load the long-format data directly into Jamovi.

  • Open jamovi and create a new file.
  • Drag and drop stren_long.csv into the data pane, or use File > Open.
  • Verify variables: id (ID, nominal), trt (Treatment, nominal), time (Time, continuous), strength (Strength, continuous).
  • If needed, right-click variables to set types (e.g., id and trt as Nominal).

Open dataset

Open dataset
  • What this does: Loads long-format data (one row per measurement), with time in days (0,2,4,6,8,10,12), and removes NAs.
  • Expected output: ~200-250 rows (some missings). Means: strength ~80-82 increasing over time; ~16 subjects trt=1, ~21 trt=2; measurements per time ~30-37.

4 Prepare the Dataset

jamovi will try to automatically idetify the type of variables in the dataset but it not always correct. In this case we need to:

  • Change the type of the variables time and strength from nominal to continuous.
  • And you can also add the labels to the trt categories

Change type of variable

Add treatment labels

Add treatment labels

5 Summarise and visualise the Data

Use the Descriptives module for summaries and the Exploration module for a spaghetti plot.

  • Go to Analyses > Exploration > Descriptives.
    • Variables: Drag strength to Dependent Variables.
    • Plots: Check “Plot” for histogram/boxplot.
    • Split by: Drag trt to Split.

Descriptives stats

Some descriptive statistics
  • For the spaghetti plot we will use the module to write the code in R (there is no current plot module that can to these plots). Use the R editor as in the animated image below and copy paste the R code:
# Spaghetti plot
library(ggplot2)
ggplot(data, 
       aes(x = time, 
           y = strength, 
           color = factor(trt), 
           group = id)) +
  geom_line(alpha = 0.6) +
    stat_summary(fun=mean, 
                 geom="line",
                 show.legend = F, 
                 lwd=3, 
                 aes(group=trt)) +
    # geom_smooth(aes(group = trt), method = "lm", se = TRUE) + #linear trend 
  labs(title = "Strength Over Time by Treatment Group",
       x = "Time (Days)", y = "Strength", 
       color = "Treatment (1=Reps, 2=Weight)") +
  theme_minimal()

Spaghetti plot with R

Spaghetti plot with R
  • What this does: Summarizes data by group; plots individual trajectories (lines per id) and group trends.

6 Fit a Basic Random Intercept Model

Model strength as function of time and trt, with random intercept per subject.

  • Go to Analyses > Linear Models> Linear Mixed Models

Liner modules menu

Liner modules menu

Liner modules menu

Liner modules menu

Liner modules menu

Liner modules menu
  • Compute predicted values: In the module, check “Predicted values” under Additional options (adds column to data).

  • For visualization: Use the plot options in the module or export predictions.

    • [Screenshot placeholder: Predicted spaghetti plot]
  • What this does: Fixed effects: intercept, time slope, trt effect; random: subject-specific deviation from intercept.

  • Expected output: Positive time coef ; trt coef ( positive for trt=2); random SD (between-subject variability). p-values from the table.

7 Compare to Ordinary Linear Model (For Illustration)

Ignore clustering with ordinary linear regression.

  • Go to Analyses > Regression > Linear regression.

    • Dependent Variable: strength.
    • Covariates: time and trt.
  • Compare coefficients/SEs from the LMM output.

  • [Screenshot placeholder: Linear regression results table]

  • Expected: lm SEs smaller (underestimates uncertainty); biased p-values. LMM SEs larger, more conservative.

8 Add Treatment-Time Interaction

Allow different slopes by treatment.

  • In the Linear mixed models analysis (edit existing or new):

    • Covariates: Add interaction by selecting time and trt and clicking the * button, or manually enter time * trt.
    • Random effects: Keep id (intercept only).
    • Options: Include “Fixed effects tests” for interaction p-value.
  • Compute predicted values as before.

  • [Screenshot placeholder: Interaction model interface and predicted plot]

  • What this does: Tests if time slope differs by trt (interaction term).

  • Expected output: Interaction p<0.05? (trt=2 faster gains); main effects adjusted. Use the table for p-values.

9 Include Random Slopes

Allow subject-specific time slopes.

  • Edit the interaction model:

    • Random effects: Drag time to Random slopes (under the id grouping).
    • This adds (time | id).
    • Options: Check “Random effects tests” and “Model fit measures” (e.g., AIC/BIC).
  • Compute predicted values.

  • Compare models: View AIC/BIC in the Model fit table (lower better).

  • [Screenshot placeholder: Random slopes interface, results table, and predicted plot]

  • What this does: Random (time | id) adds subject-specific slopes; compare fit via AIC (lower better).

  • Expected output: Random slope SD; better fit (lower AIC) than intercept-only.

10 Model Diagnostics

Check assumptions using built-in plots.

  • In the Linear mixed models module (random slopes model):

    • Options > Assumptions: Check “Residuals vs fitted”, “Q-Q plot”, “Histogram of residuals”.
  • Review the generated plots.

  • [Screenshot placeholder: Diagnostics plots (residuals vs fitted, QQ, histogram)]

  • What this does: Plots check linearity/homoscedasticity; QQ for normality.

  • Expected output: Points scatter around line (no patterns); QQ straight; residuals ~normal.